/**
 * 
 */
package org.vsg.common.jobscheduler.persistence.hibernate;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import org.springframework.dao.DataAccessException;
import org.vsg.common.jobscheduler.domain.QuartzTrigger;
import org.vsg.common.jobscheduler.persistence.ScheduleJobDao;
import org.vsg.common.orm.hibernate.AbstractGenericDaoImpl;

/**
 * @author Administrator
 *
 */
public class ScheduleJobDaoImpl extends AbstractGenericDaoImpl implements
		ScheduleJobDao {

	/* (non-Javadoc)
	 * @see org.vsg.common.jobscheduler.persistence.ScheduleJobDao#listQuartzTriggerByGroup(java.lang.String)
	 */
	@Override
	public List<QuartzTrigger> listQuartzTriggerByGroup(String groupName)
			throws DataAccessException {
		// TODO Auto-generated method stub
		
		StringBuilder query = new StringBuilder("SELECT ");
		query.append("entity ");
		query.append("FROM ").append(QuartzTrigger.class.getName());
		query.append(" as entity ");
		query.append("WHERE entity.id.triggerGroup = ? ");

		Collection params = new Vector();
		params.add( groupName );
		
		
		logger.info("query : " + query.toString());
		
		java.util.Iterator<QuartzTrigger> iter = getTemplate().iterate(query.toString() , params.toArray());
		
		List<QuartzTrigger> triggerList = new LinkedList<QuartzTrigger>();
		QuartzTrigger entity = null;
		while ( iter.hasNext() ) {
			entity = iter.next();
			triggerList.add( entity );
		}
		
		return triggerList;
	}

}
